import Vue from 'vue'
import VueRouter from 'vue-router'
import Longe from '../views/longe.vue'
import Home from '../views/Home.vue'
import Wel from '../components/wel.vue'
import User from '../components/user/user.vue'
import Roules from '../components/user/roles.vue'
import Rights from '../components/user/rights.vue'
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/Longe', component: Longe },
    { path: '/Longe', component: Longe },
    { path: '/home',
      component: Home,
      redirect: '/home/welcome',
      children: [
        { path: '/home/welcome', component: Wel },
        { path: '/users', component: User },
        { path: '/roles', component: Roules },
        { path: '/rights', component: Rights }
      ]

    }
  ]
})
router.beforeEach((to, form, next) => {
  if (to.path === '/Longe') return next()
  //  获取token值
  let tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/Longe')
  next()
})
export default router
